package com.bus.core.dao.impl;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.bus.common.hibernate4.Updater;
import com.bus.common.jpa.JpaBaseDao;
import com.bus.core.dao.BusUserExtDao;
import com.bus.core.entity.BusUserExt;

@Repository
public class BusUserExtDaoImpl extends JpaBaseDao<BusUserExt, Integer> implements BusUserExtDao {
	public BusUserExt findById(Integer id) {
		BusUserExt entity = get(id);
		return entity;
	}

	public BusUserExt save(BusUserExt bean) {
		getEntityManager().persist(bean);
		return bean;
	}
	
	@Override
	protected Class<BusUserExt> getEntityClass() {
		return BusUserExt.class;
	}
	
	public void clearDayCount(){
		String hql="update BusUserExt ext set ext.todayGuestbookTotal=0,ext.todayCommentTotal=0";
		getEntityManager().createQuery(hql).executeUpdate();
	}
	@Override
	public int countByPhone(String mobile) {
		String hql = "select count(*) from BusUserExt bean where bean.mobile = :mobile";
		Query query = getEntityManager().createQuery(hql);
		query.setParameter("mobile", mobile);
		return ((Number)query.getSingleResult()).intValue();
	}

	@Override
	public BusUserExt updateByUpdater(Updater<BusUserExt> updater) {
		// TODO Auto-generated method stub
		return null;
	}

}